package com.zzl.mq.network.http;

import com.zzl.mq.network.gossip.GossipManager;
import com.zzl.mq.network.gossip.GossipMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/gossip")
public class GossipController {

    private final GossipManager gossipManager;

    @Autowired
    public GossipController(GossipManager gossipManager) {
        this.gossipManager = gossipManager;
    }

    @PostMapping
    public ResponseEntity<?> receiveGossipMessage(@RequestBody GossipMessage message) {
        try {
            gossipManager.handleGossipMessage(message);
            return ResponseEntity.ok().build();
        } catch (Exception e) {
            return ResponseEntity.status(500).body("Failed to process gossip message");
        }
    }
} 